<?php
/**
 * Created by Sven.
 * Date: 2016/12/31
 * Time: 19:07
 */

//var_dump($_GET);
//var_dump($_POST);
//var_dump($_FILES);

include dirname( dirname( __FILE__ ) ) . '/includes/init.inc.php';

$_ckefn =  $_GET['CKEditorFuncNum'];

if ( IS_POST ) {
    if ( $_POST ) {
        $_POST[ 'MAX_FILE_SIZE' ] = 204800;
        $_upload = new FileUpload( 'upload', $_POST[ 'MAX_FILE_SIZE' ]);
        if ( $_upload->upload() ) {
            $_linkPath = '/'.$_upload->getLinkPath();
//            exit($_linkPath);
            echo <<<EOF
<script>
    window.parent.CKEDITOR.tools.callFunction($_ckefn,"{$_linkPath}",'图片上传成功');
</script>
EOF;

        }
    } else {
        exit( '警告：可能因为文件过大，导致上传失败' );
    }

} else {
    exit( '警告：禁止GET方式访问此脚本' );
}